// api/log_api/log_remove.go
package log_api

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"muziai-server/global"
	"muziai-server/models"

	"muziai-server/utils/jwts"
	"muziai-server/utils/res"
)

func (LogApi) LogRemoveView(c *gin.Context) {

	var cr models.IDListRequest
	err := c.ShouldBindJSON(&cr)
	if err != nil {
		res.FailWithError(c, err)
		return
	}

	query := global.DB.Where("")
	_claims, _ := c.Get("claims")
	claims := _claims.(*jwts.Claims)
	if claims.IsAuth() {
		query.Where("user_id = ?", claims.UserID)
	}

	var logList []models.LogModel
	global.DB.Where(query).
		Find(&logList, "id in ?", cr.IDList).Delete(&logList)

	res.OkWithMsg(c,
		fmt.Sprintf("删除日志%d条，成功%d条",
			len(cr.IDList), len(logList)))
}
